home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / RxSlides / color_util.c < prev    next >
C/C++ Source or Header  |  1990-03-08  |  2KB  |  85 lines

  1. /* :bk=0 */
  2.  
  3. /************************************************************************/
  4. /*                                    */
  5. /*                        Color_util.c        */
  6. /*                                    */
  7. /* Author: Lee M. Robertson and Dean Bandes                */
  8. /*    Based on an article in the Nov '86 Doctor Dobb's Journal     */
  9. /*    by Mike Morton                            */
  10. /*                                    */
  11. /************************************************************************/
  12.  
  13. #include "exec/types.h"
  14. #include "exec/memory.h"
  15. #include "intuition/intuition.h"
  16. #include "RxSlides.h"
  17.  
  18. static    UWORD    ColorTable[32];
  19.  
  20. /*---------------------------------------------------------------------------
  21.  * setcolors() -- set the color registers
  22.  *-------------------------------------------------------------------------*/
  23. void setcolors( vp, creg, numcolors )
  24. struct ViewPort *vp;
  25. register UBYTE *creg;            /* the color values */
  26. int numcolors;                /* the # of colors to set */
  27. {
  28.     register ULONG r,g,b;        /* the RGB color values (temporaries) */
  29.     register int i;
  30.  
  31.     for(i=0; i<numcolors; i++)
  32.     {
  33.         r = *creg++ >> 4;
  34.         g = *creg++ >> 4;
  35.         b = *creg++ >> 4;
  36.         ColorTable[i] = ((r & 0x00f) << 8) |
  37.                 ((g & 0x00f) << 4) |
  38.                 (b & 0x00f);
  39.     }
  40.     WaitTOF();
  41.     LoadRGB4(vp, ColorTable, numcolors);
  42. }
  43.  
  44. /*---------------------------------------------------------------------------
  45.  *
  46.  *-------------------------------------------------------------------------*/
  47. void fadecolors( vp, creg1, creg2, num, denom, numcolors)
  48. struct ViewPort *vp;
  49. register UBYTE *creg1, *creg2;
  50. int num, denom, numcolors;
  51.   {
  52.   register ULONG r,g,b;            /* the RGB color values (temporaries) */
  53.   register int i, diff;
  54.  
  55.   if ( num > denom )
  56.     num = denom;
  57.   if ( num < 0 )
  58.     num = 0;
  59.  
  60.   diff = denom - num;
  61.   for(i=0; i<numcolors; i++)
  62.     {
  63.     r = (((diff * (int) *creg1++) + (num * (int) *creg2++)) / denom) >> 4;
  64.     g = (((diff * (int) *creg1++) + (num * (int) *creg2++)) / denom) >> 4;
  65.     b = (((diff * (int) *creg1++) + (num * (int) *creg2++)) / denom) >> 4;
  66.     ColorTable[i] = ((r & 0x00f) << 8) |
  67.             ((g & 0x00f) << 4) |
  68.             (b & 0x00f);
  69.     }
  70.   WaitTOF ();
  71.   LoadRGB4(vp, ColorTable, numcolors);
  72.   }
  73.  
  74. /*---------------------------------------------------------------------------
  75.  *
  76.  *-------------------------------------------------------------------------*/
  77. void savecolors (dest, src)
  78. UBYTE *dest, *src;
  79.  
  80.   {
  81.   int i;
  82.   for (i=0; i<CMSIZE; i++)
  83.     *dest++ = *src++;
  84.   }
  85.